package com.tancire.web.controller.platform.message;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.message.domain.MsgMessage;
import com.tancire.message.service.IMsgMessageService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 消息管理Controller
 *
 * @author tancire
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/message/msgMessage")
public class MsgMessageController extends BaseController {
    @Resource
    private IMsgMessageService msgMessageService;

    /**
     * 查询消息管理列表
     */
    @PreAuthorize("@ss.hasPermi('message:msgMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(MsgMessage msgMessage) {
        startPage();
        List<MsgMessage> list = msgMessageService.selectMsgMessageList(msgMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息管理列表
     */
    @PreAuthorize("@ss.hasPermi('message:msgMessage:export')")
    @Log(title = "消息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MsgMessage msgMessage) {
        List<MsgMessage> list = msgMessageService.selectMsgMessageList(msgMessage);
        ExcelUtil<MsgMessage> util = new ExcelUtil<MsgMessage>(MsgMessage.class);
        util.exportExcel(response, list, "消息管理数据");
    }

    /**
     * 获取消息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:msgMessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(msgMessageService.selectMsgMessageById(id));
    }

    /**
     * 新增消息管理
     */
    @PreAuthorize("@ss.hasPermi('message:msgMessage:add')")
    @Log(title = "消息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MsgMessage msgMessage) {
        return toAjax(msgMessageService.insertMsgMessage(msgMessage));
    }

    /**
     * 修改消息管理
     */
    @PreAuthorize("@ss.hasPermi('message:msgMessage:edit')")
    @Log(title = "消息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MsgMessage msgMessage) {
        return toAjax(msgMessageService.updateMsgMessage(msgMessage));
    }

    /**
     * 删除消息管理
     */
    @PreAuthorize("@ss.hasPermi('message:msgMessage:remove')")
    @Log(title = "消息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(msgMessageService.deleteMsgMessageByIds(ids));
    }
}
